<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>循环输出 HTML 标题</title>
</head>

<body>
    <p>单击按钮将HTML标题设置从1到6的样式显示</p>
    <button onclick="myFunction()">点我</button>
    <div id="demo"></div>
    <script>
        function myFunction() {
            var x = "", i;
            for (i = 1; i <= 6; i++) {
                x = x + "<h" + i + ">Heading " + i + "</h" + i + ">";
            }
            document.getElementById("demo").innerHTML = x;
        }
    </script>
</body>

</html>